package com.tanhua.server.controller;


import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.SettingsVo;
import com.tanhua.server.interceptor.UserThreadLocal;
import com.tanhua.server.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("users")
public class SettingController {

    @Autowired
    private SettingService settingService;

    /**
     * 查询配置
     *
     * @return
     */
    @GetMapping("settings")
    public ResponseEntity<SettingsVo> querySettings() {
        return settingService.querySettings();
    }

    /**
     * 设置陌生人问题
     */
    @PostMapping("questions")
    public ResponseEntity<Void> saveQuestions(@RequestBody Map<String, String> param) {
        String content = param.get("content");
        return this.settingService.saveQuestions(content);
    }

    /**
     * 查询黑名单
     */
    @GetMapping("blacklist")
    public ResponseEntity<PageResult> queryBlacklist(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize) {
        return settingService.queryBlacklist(page,pagesize);
    }

    /**
     * 移除黑名单
     */
    @DeleteMapping("blacklist/{uid}")
    public ResponseEntity<Void> delBlacklist(@PathVariable("uid") Long userId) {
        return settingService.delBlacklist(UserThreadLocal.getUserId(),userId);
    }

    /**
     * 更新通知设置
     */
    @PostMapping("notifications/setting")
    public ResponseEntity<Void> updateNotification(@RequestBody Map<String, Boolean> param) {
        Boolean likeNotification = param.get("likeNotification");
        Boolean pinglunNotification = param.get("pinglunNotification");
        Boolean gonggaoNotification = param.get("gonggaoNotification");
        return settingService.
                updateNotification(likeNotification, pinglunNotification, gonggaoNotification);
    }

}
